package com.huyanqi.front.rest.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.huyanqi.core.RetdCodeType;
import com.huyanqi.core.RetdObj;
import com.huyanqi.core.service.impl.BaseFrontServiceImpl;
import com.huyanqi.dao.ShareDAO;
import com.huyanqi.entity.Share;
import com.huyanqi.front.rest.service.ShareRestService;

@Service("ShareRestService")
public class ShareRestImpl extends BaseFrontServiceImpl<Share,Long, ShareDAO> implements ShareRestService{

	@Override
	@Resource(name="ShareDAO")
	public void setEntityDao(ShareDAO entityDao) {
		this.entityDao=entityDao;
	}

	@Override
	public RetdObj<List<Share>> findLatestShare(Integer pageSize,Integer pageNum) {
		RetdObj<List<Share>> retd = new RetdObj<List<Share>>();
		List<Share> list = entityDao.executeQuery("SELECT new Share(s.usId,s.usImg,s.usUid,s.usTime,s.usContent,u.uNickname,u.uHead) FROM Share s,User u WHERE s.usUid = u.uId GROUP BY s.usId ORDER BY s.usTime DESC");
		if(list!=null){
			retd.setRealObj(list);
			retd.setCode(RetdCodeType.PASS_OK);
		}else{
			retd.setCode(RetdCodeType.PASS_NODATA);
		}
		return retd;
	}
	
	@Override
	public RetdObj<List<Share>> findMyShare(Long uid) {
		RetdObj<List<Share>> retd = new RetdObj<List<Share>>();
		List<Share> list = entityDao.executeQuery("FROM Share WHERE usUid = ? ORDER BY usTime DESC", uid);
		if(list!=null){
			retd.setRealObj(list);
			retd.setCode(RetdCodeType.PASS_OK);
		}else{
			retd.setCode(RetdCodeType.PASS_NODATA);
		}
		return retd;
	}
	
}
